package com.btex.app.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.FuturesListInfo;
import com.btex.app.tools.SharedPreferencesUtil;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author zhangyi<zhangyi, 1104745049@qq.com>
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/12/27
 * @time 下午3:01
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */


public class HomeHeYuePageAdapter extends BaseQuickAdapter<FuturesListInfo.DataBean, BaseViewHolder> {

    public HomeHeYuePageAdapter(@Nullable List<FuturesListInfo.DataBean> data) {
        super(R.layout.item_shou_ye_recy, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, FuturesListInfo.DataBean item) {
        SharedPreferencesUtil sharedPreferences = SharedPreferencesUtil.getSharedPreferences(MyApplication.getContextObject());


//        市场
        TextView item_news_type = (TextView) helper.getView(R.id.item_news_type);
//        价格
        TextView item_news_price = (TextView) helper.getView(R.id.item_news_price);
//        涨跌
        TextView item_news_zhang_die = (TextView) helper.getView(R.id.item_news_zhang_die);
//        折合
        TextView item_news_money = (TextView) helper.getView(R.id.item_news_money);
//        结算
        TextView jiesuan = (TextView) helper.getView(R.id.jiesuan);

        item_news_money.setVisibility(View.GONE);
        jiesuan.setVisibility(View.VISIBLE);

        String settle_anchor = item.getSettle_anchor();
        String contract_anchor = item.getContract_anchor();
        String price_float_num = item.getPrice_float_num();
        String pair = item.getPair();
        String symbol = item.getSymbol();
        String change_24h = item.getTicker().getChange_24h();
        String mark_price = item.getTicker().getTrade_price();

        try {

            String[] strs = pair.split("_");
            String newType = strs[0] + strs[1];
            jiesuan.setText("(" + settle_anchor + mContext.getString(R.string.item_settle) + ")");
//        item_news_type.setText(contract_anchor + settle_anchor);
            item_news_type.setText(newType);

        } catch (Exception e) {

        }
//        String[] strs = pair.split("_");
//        String newType = strs[0] + strs[1];
//        jiesuan.setText("(" + settle_anchor + "结算" + ")");
////        item_news_type.setText(contract_anchor + settle_anchor);
//        item_news_type.setText(newType);

        if (Double.valueOf(mark_price) == 0) {
            item_news_price.setText("0.00");
        } else {
            String s = Tools.round(Double.valueOf(mark_price), Integer.valueOf(price_float_num)).toString().toString();
            item_news_price.setText(s);
        }


        Double aDoublechange24h = Double.valueOf(change_24h);
        if (aDoublechange24h == 0) {
            item_news_zhang_die.setText("+0.00%");
        } else {
            if (aDoublechange24h < 0) {
                String trim = Tools.round(Double.valueOf(change_24h) * 100, 2).toString().trim();
                item_news_zhang_die.setText(trim + "%");
            } else {
                String trim = Tools.round(Double.valueOf(change_24h) * 100, 2).toString().trim();
                item_news_zhang_die.setText("+" + trim + "%");
            }

        }


        item_news_zhang_die.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.white));
        if (aDoublechange24h > 0 || aDoublechange24h == 0) {

            item_news_zhang_die.setBackgroundResource(R.drawable.item_bg_no);

        } else {
            item_news_zhang_die.setBackgroundResource(R.drawable.item_bg);
        }


    }
}
